package com.woniuxy.controller;

import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.Test;
import com.woniuxy.service.TestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * (Test)表控制层
 *
 * @author zjx
 * @since 2021-05-14 19:42:03
 */
@Api(value = "试题管理接口")
@RestController
@RequestMapping("test")
public class TestController {
    /**
     * 服务对象
     */
    @Resource
    private TestService testService;



    @ApiOperation("查询除去题库id的所有试题信息")
    @PostMapping("queryByTestBankId")
    public ResponseEntity queryByTestBankId(@ApiParam("题库id,模糊查询所需信息")@RequestBody Map<String,Object> map){
        Map<String,Object> info = this.testService.queryByTestBankId(map);

        if(info == null){
            return new ResponseEntity(200,"NO",null);
        }
        return new ResponseEntity(200,"OK",info);

    }

    @ApiOperation("展示试题信息")
    @PostMapping("queryAll")
    public ResponseEntity queryAll(@ApiParam("起始页，页面条数，TestInfo的map对象")@RequestBody Map<String,Object> map){
//        System.out.println("进入试题展示==="+map);
        PageInfo<Map<String,String>> pageInfo = this.testService.queryAll(map);
        return new ResponseEntity(200,"OK",pageInfo);
    }
    /**
     * Description : 插入一条完整的试题信息
     * ChangeLog : 1. 创建 (2021/5/17 14:04 [zjx]);
     * @param test，包含test类，List<TestLabel>分装对象，List<TestOptions>封装对象
     * @return null
    */
    @ApiOperation("添加试题")
    @PostMapping("insertOne")
    public ResponseEntity insertOne(@ApiParam("试题相关信息")@RequestBody Map<String,Object> test){
        int row = this.testService.insertOne(test);
        return new ResponseEntity(200,"success",row);
    }
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation("查询一条试题信息")
    @GetMapping("selectOne")
    public Test selectOne(@ApiParam("试题id") Integer id) {
        return this.testService.queryById(id);
    }
    /**
     * Description : 插入一条数据
     * ChangeLog : 1. 创建 (2021/5/15 17:29 [zjx]);
     * @param test 试题类
     * @return null
    */
    @ApiOperation("插入一条试题信息")
    @PostMapping("/insert")
    public Test insert(@ApiParam("试题类数据")@RequestBody Test test){
        return this.testService.insert(test);
    }
    /**
     * Description : 更新一条数据
     * ChangeLog : 1. 创建 (2021/5/15 17:37 [zjx]);
     * @param test
     * @return null
    */
    @ApiOperation("更新一条试题信息")
    @PutMapping("update")
    public Test update(@ApiParam("试题类数据")@RequestBody Test test){
        return this.testService.update(test);
    }

    /**
     * Description : 删除一条数据
     * ChangeLog : 1. 创建 (2021/5/15 17:41 [zjx]);
     * @param id 试题id
     * @return null
    */
    @ApiOperation("删除一条试题信息")
    @DeleteMapping("deleteById")
    public boolean deleteById(@ApiParam("试题id") Integer id){
        return this.testService.deleteById(id);
    }

}
